package com.igeekhome.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.INoticeService;
import com.igeekhome.biz.ISystemMessageService;
import com.igeekhome.pojo.Notice;
import com.igeekhome.pojo.SystemMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 系统信息 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-16
 */
@Controller
@RequestMapping("/systemMessage")
public class SystemMessageController {

    @Autowired
    private ISystemMessageService iSystemMessageService;
    @RequestMapping("/sm")
    public String sm(Model model, HttpSession session, @RequestParam("value")String value,@RequestParam("current")Integer current, @RequestParam("size")Integer size){


        IPage<SystemMessage> page =new Page<>(current,size);

        QueryWrapper<SystemMessage> qw = new QueryWrapper<>();
        qw.like("title",value).or().like("content",value);
        IPage<SystemMessage> page1=this.iSystemMessageService.page(page,qw);
        List<SystemMessage> list = page1.getRecords();
        session.setAttribute("notice",this.iSystemMessageService.count());
        long pagesCount=page1.getPages();
        model.addAttribute("list",list);
        model.addAttribute("pagesCount",pagesCount);
        return "systemMessage";
    }
}

